import DialogForm from '@/utils/tools/DialogForm'
import { savebsProBiddingApi, editbsProBiddingApi, bsProBiddingApigeById, deletebsProBiddingApi } from '@/apiList/api_power'
import { isEmail, isTel } from '@/utils/tools/validate'
// 招标管理
export default class Dialog extends DialogForm {
  paramsFormat(formData) {
    console.log(formData);
    if(formData.userInfo.signStartDate){
      let date=JSON.parse(JSON.stringify(formData.userInfo.signStartDate))
      delete formData.userInfo.signStartDate
      formData.userInfo.signStartDate=date[0]
      formData.userInfo.signEndDate=date[1]
    }
    return {
      ...formData
    }
  }
  // 新增提交 - 1
  async addSubmit(formData) {
    const params = this.paramsFormat(formData)

    await savebsProBiddingApi(params.userInfo)
  }
  // 编辑打开弹窗
  async editOpenDialog(row) {
    let res = await this.getByIdInfo(row)
    await this.addOpenDialog()
    this.submitType = 1
  
    let copyData=JSON.parse(JSON.stringify(res))
    copyData.signStartDate=[res.signStartDate,res.signEndDate]
    this.setData({
      addFormData: {
        userInfo: copyData
      }
    })
  }
  // 编辑提交 - 2
  async editSubmit(row) {
    
    const params = this.paramsFormat(this.data.addFormData)
    
    await editbsProBiddingApi({ id: row.id, ...params.userInfo })
  }
  // 表单验证 - 3
  async fromDataVali(data) {
    const f = data.userInfo
  
    // if (!f.noticeTitle) return this.$alert('请输入公告标题')
    // if (!f.projectName) return this.$alert('请输入项目名称')

    // if (f.sysRoleIds.length == 0) return this.$alert('请选择账户类别')

    // if (f.purchasePhone && !isTel(f.purchasePhone)) return this.$alert('请输入正确的联系人手机号')
   
    return true
  }
  // 删除提交 - 4
  async delSubmit(rowList) {
    let ids = rowList.map((e) => e.id).toString()
    await deletebsProBiddingApi({ id: ids })
  }
  // 更新列表 - 5
  async updateList() {
    this.data.getList() // 调用父级列表更新
  }
  // 通过id获取详情 - 6
  async getByIdInfo(id) {
    let res = await bsProBiddingApigeById({ id: id,  })
    return res
  }
}
